import {Component} from "@angular/core";
import {UserService} from "./service/user.service";
import {User} from "./entity/user";

@Component({
    selector: 'my-app',
    templateUrl: "./app/app.html",
    providers:[UserService]
})
export class AppComponent {

    private user:User = {"name":"jack", "age":25, "married":false};

    //使用DI (构造函数注入) <========= 推荐使用的写法
    // private userService:UserService;
    private userArray:User[];

    constructor(userService:UserService){
        console.log("AppComponent 有参构造...");
        // this.userService = userService;
        this.userArray = userService.getAll();
    }

    //不使用 DI
    // private userService:UserService = new UserService();
    // private userArray:User[] = this.userService.getAll();

    // private userArray:User[] = new UserService().getAll();

    /*private userArray:User[];
    constructor(){
        console.log("AppComponent 空参构造...");
        this.userArray = new UserService().getAll();
    }*/
    


}
